package com.yfore.jfinal.pdf.plugin;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

import org.xhtmlrenderer.pdf.ITextRenderer;

import com.jfinal.plugin.IPlugin;

/**
 * 
 * @author farmer
 *
 */
public class PdfPlugin implements IPlugin{
	
	/**
	 * iTextRenderer 实例
	 */
	ITextRenderer iTextRenderer = ITextRendererObjectFactory.createTextRenderer();
	
	private List<String> fonts = null;
	
	/**
	 * 
	 * @param fonts
	 * 	外部字体路径
	 */
	public PdfPlugin(List<String> fonts){
		this.fonts = fonts==null?new ArrayList<String>():fonts;
	}
	
	@Override
	public boolean start() {
		for (String font : fonts) {	//添加字体到ITextRenderer
			if(new File(font).isDirectory()){
				ITextRendererObjectFactory.addFonts(font);
			}else{
				ITextRendererObjectFactory.addFont(font);
			}
		}
		PdfKit.init(iTextRenderer);
		return true;
	}

	@Override
	public boolean stop() {
		return true;
	}

	
	
}
